<template>
	<div>
		<div>
			<el-form :model="userLogin" status-icon :rules="rules" ref="userLogin" label-width="100px"
				class="demo-ruleForm">
				<el-form-item label="账号" prop="username">
					<el-input type="username" v-model="userLogin.username" autocomplete="off"></el-input>
				</el-form-item>

				<el-form-item label="密码" prop="password">
					<el-input type="password" v-model="userLogin.password" autocomplete="off"></el-input>
				</el-form-item>
		
		<div style="text-align: center;">
			<el-form-item>
				<el-button type="primary" @click="submitForm('userLogin')">登录</el-button>
				<el-button>
					<router-link to="/register" tag="span">注册</router-link>
				</el-button>
			</el-form-item>
		</div>
		</el-form>
</div>
		<el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
			<span>登录成功点击确认进入</span>
			<span slot="footer" class="dialog-footer">

				<el-button type="primary" @click="dialogVisible = false">
					<router-link to="/Leading_end/" tag="span">确 认</router-link>
				</el-button>
			</span>
		</el-dialog>
	</div>
</template>


<script>
	export default {
		data() {
			var validatePass = (rule, value, callback) => {
				if (value === '') {
					callback(new Error('请输入密码'));
				} else {
					if (this.userLogin.checkPass !== '') {
						this.$refs.userLogin.validateField('checkPass');
					}
					callback();
				}
			};
			var validateUser = (rule, value, callback) => {
				if (value === '') {
					callback(new Error('请输入账号'));
				} else {

				}
				callback();
			}


			return {
				dialogVisible: false,
				userLogin: {
					password: '',
					username: ''

				},
				rules: {

					password: [{
						validator: validatePass,
						trigger: 'blur'
					}],
					username: [{
						validator: validateUser,
						trigger: 'blur'
					}],

				}
			};
		},
		methods: {

			login(done) {
				this.axios.get("http://localhost:8085/users/" + this.userLogin.username + "/" + this.userLogin.password +
					"/login").then(res => {
					if (res.data.code == 200) {
						this.dialogVisible = true
					} else {
						this.$message.error(res.data.msg);
					}


				})
			},
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						//测试
						this.login();

					} else {
						console.log('error submit!!');
						return false;
					}
				});
			}

		}
	}
</script>

<style>
</style>
